import type {ChatMessage, ChatPreListItem} from "@/interface/Chat";
import {request} from "@/utils/request";
import type {PageResult} from "@/types/PageResult";

/*
用户id由后端判断
 */
export const getUserChatListApi = (page: number, pageSize: number) => {
    return request<PageResult<ChatPreListItem[]>>({
        url: '/user/chat/list?page=' + page + '&pageSize=' + pageSize,
        method: 'GET'
    })
}

/**
 * 获取用户历史聊天数据
 * @param page
 * @param pageSize
 * @param receiverId
 * @param linkId
 */
export const getChatHistoryListApi = (page: number, pageSize: number, receiverId: number, linkId?: number) => {
    return request<PageResult<ChatMessage[]>>({
        url: '/user/chat/history?page=' + page + '&pageSize=' + pageSize + '&receiverId=' + receiverId + '&linkId=',
        method: 'GET'
    })
}

/**
 * 获取用户收到的未查看的聊天数
 */
export const getNewChatNumApi = () => {
    return request<number>({
        url: '/user/chat/new/num',
        method: 'GET'
    })
}

/**
 * 获取用户聊天linkId
 * @param chatUserId
 */
export const getChatLinkIdApi = (chatUserId: number) => {
    return request<number>({
        url: '/user/chat/linkId?chatUserId=' + chatUserId,
        method: 'GET'
    })
}

/**
 * 清除用户未读
 */
export const clearUnreadApi=()=>{
    return request({
        url:'/user/chat/clear/unread',
        method:'POST'
    })
}